﻿using System;

namespace Alex.Library.Web.Ajax
{
    /// <summary>
    /// Http请求类型
    /// </summary>
    public enum HttpRequestType
    {
        GET,
        POST,
        ALL
    }

    /// <summary>
    /// 被用于Ajax的方法特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
    public class AjaxMethodAttribute : Attribute
    {
        /// <summary>
        /// 方法名称，为空表示使用方法名
        /// </summary>
        public string MethodName { get; set; }

        /// <summary>
        /// 限制可用的Http请求
        /// </summary>
        public HttpRequestType RequestType { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="methodName">Ajax方法名</param>
        /// <param name="requestType">可接受的请求类型</param>
        public AjaxMethodAttribute(string methodName, HttpRequestType requestType)
        {
            this.MethodName = methodName;
            this.RequestType = requestType;
        }

        /// <summary>
        /// 构造函数，默认接受全部类型的请求
        /// </summary>
        /// <param name="methodName">Ajax方法名</param>
        public AjaxMethodAttribute(string methodName) : this(methodName, HttpRequestType.ALL) { }

        /// <summary>
        /// 默认构造函数，Ajax方法名默认为方法名，并接受全部类型的请求
        /// </summary>
        public AjaxMethodAttribute() : this(String.Empty) { }
    }
}
